package org.vector.view;

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

import org.vector.serviceImpl.BankServiceImpl;

@SuppressWarnings("serial")
public class WindowSave extends JFrame{
	BankServiceImpl bsi = new BankServiceImpl();
	private JTextField t1;
	private JPasswordField ps;
	private JLabel l1,l2,l3;
	private JButton btn1,btn2;
	
	
	public WindowSave() {}
	public WindowSave(int bankid) {
		into(bankid);
		setVisible(true);
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
	}

	private void into(int bankid ) {
		setSize(300, 500);
		setLocationRelativeTo(null);
		setLayout(new FlowLayout());
		
		l1 = new JLabel("存款");
		add(l1);
		
		//p = new JPanel();
		//p.setLayout(new FlowLayout());
		l2 = new JLabel("存款金额");
		t1 = new JTextField(20);
		l3 = new JLabel("支付密码");
		ps = new JPasswordField(20);
		add(l2);
		add(t1);
		add(l3);
		add(ps);
		//add(p,BorderLayout.CENTER);
		
		//down = new JPanel();
		btn1 = new JButton("取消");
		btn2 = new JButton("确定");
		add(btn1);
		add(btn2);
		
		btn1.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				WindowSave.this.dispose();
			}
		});
		btn2.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				String t11 = t1.getText();
				int t12 = Integer.valueOf(t11);//钱数
				//密码
				String pwd = new String(ps.getPassword());
				int ps1 = Integer.valueOf(pwd);
				int rows = bsi.save(ps1, t12-3, bankid);
				if(rows == 1) {
					WindowSave.this.dispose();
					new Wcuowu("操作成功");
					Date date = new Date();
					SimpleDateFormat sdf =
							new SimpleDateFormat("yyMMddHHmm");
					String s = sdf.format(date);
					int gouwuid = (int)(Math.random()*(10000-1000+1)+1000);
					bsi.savedaytoday(gouwuid, bankid, bankid, t12, 3, "存款", s);
					
					
				}else {
					new Wcuowu("操作失败");
				}
			}
		});
		
	}
}
